<template>
  <div class="home-container">
    <!-- 导航栏 -->
    <van-nav-bar class="page-nav-bar" fixed="">
      <van-button
        class="search-btn"
        slot="title"
        type="info"
        size="small"
        round
        icon="search"
        to="/search"
        >搜索</van-button
      >
    </van-nav-bar>
    <!-- /导航栏 -->
    <!-- 频道列表 -->
    <!-- v-model	绑定默认当前选中标签的标识符  animated动画效果  swipeable滑动 -->
    <van-tabs class="channel-tabs" v-model="active" animated swipeable>
      <van-tab
        v-for="channel in channels"
        :key="channel.id"
        :title="channel.name"
      >
        <Article :channel="channel"></Article>
      </van-tab>
      <!-- 插槽部分 -->
      <div slot="nav-right" class="placeholder">123</div>
      <div
        slot="nav-right"
        class="hamburger-btn"
        close-icon-position="top-left"
        @click="isChannelEdShow = true"
      >
        <i class="iconfont icon-gengduo"></i>
      </div>
    </van-tabs>

    <!-- 编辑 -->
    <van-popup
      v-model="isChannelEdShow"
      closeable=""
      close-icon-position="top-right"
      position="bottom"
      :style="{ height: '100%' }"
    >
      <!-- 频道列表 -->
      <channel-edit :myChannels="channels" :active="active" @updataChange="sss">
      </channel-edit>
    </van-popup>
   
  </div>
</template>

<script>

import { getUserChannels } from "@/api/user";
import Article from "./components/article.vue";
import ChannelEdit from "./components/channel-edit.vue";

export default {
  name: "HomePage",
  components: {
    Article,
    ChannelEdit,
  
  },
  props: {
    // hchannels:{
    //   type:Array,
    //   required:true
    // }
  },
  data() {
    return {
      active: 0,
      channels: [], //频道列表
      list: [],
      isChannelEdShow: true,
    };
  },
  computed: {},
  watch: {},
  created() {
    this.loadChannels();
  },
  mounted() {},
  methods: {
    async loadChannels() {
      try {
        const { data } = await getUserChannels();
        this.channels = data.data.channels;
      } catch (err) {
        this.$toast("获取频道数据失败");
      }
    },
    sss(index) {
      console.log('home',index);
      this.active = index;
      this.isEdit = false;
    },
  },
};
</script>

<style scoped lang="less">
//  ....导航栏样式 ...
.home-container {
  padding-bottom: 100px;
  padding-top: 174px;
  .page-nav-bar {
    background-color: blue;
  }

  // >>>  element ui里面的样式穿透
  //  /deep/修改组件样式
  /deep/.van-nav-bar__title {
    max-width: unset; //或者设置为none
    // unset 关键字我们可以理解为不设置，
  }
  .search-btn {
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border: none;
    font-size: 28px;
    i.iconfont {
      font-size: 32px;
    }
  }
}
// ...导航栏样式....

// ...频道列表样式... 改变组件样式用/deep/
/deep/ .channel-tabs {
  .van-tabs__wrap {
    height: 82px;
    top: 92px;
    position: fixed;
    z-index: 2;
    left: 0;
    right: 0;
  }
  .van-tab {
    border-right: 1px solid #edeff3;
    font-size: 30px;
    color: #777777;
    min-width: 200px;
    height: 80px;
  }
  .van-tab-avtive .van-tab__title {
    color: #333333 !important;
  }
  .nav-tabs__nav {
    padding-bottom: 0;
    .van-tabs__line {
      width: 31px !important;
      height: 6px;
      background-color: #3296fa;
      border-radius: 3px;
      bottom: 8px;
    }
  }

  .hamburger-btn {
    position: fixed;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 66px;
    height: 82px;
    background-color: #fff;
    background-image: linear-gradient(
      transparent,
      rgba(222, 222, 222, 0.5, transparent)
    );
    opacity: 0.902;
    i.iconfont {
      font-size: 33px;
    }
    &:before {
      // content是插入生成的内容，一
      // 般与伪元素:befor和:after配合使用。表示在需要的地方插入"."。
      content: "";
      position: absolute;
      left: 0;
      width: 2px;
      height: 100%;
      // background-image: url(~@/assets/gradient-gray-line.png);
      background-size: contain;
    }
  }
  .placeholder {
    flex-shrink: 0;
    // flex-shrink 属性指定了 flex 元素的收缩规则。flex 元素仅在默认
    // 宽度之和大于容器的时候才会发生收缩，其收缩的大小是依据 flex-shrink 的值。
    //  默1认1
    width: 66px;
    height: 82px;
  }
}
// ....频道样式....

//
</style>